import { Injectable, NestMiddleware } from '@nestjs/common'
import { Request, Response, NextFunction } from 'express'

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
	use(req: Request, res: Response, next: NextFunction) {
		console.log('app：中间件 LoggerMiddleware')
		const authorization = req.headers.authorization || ''
		if (authorization && !authorization.startsWith('Bearer')) {
			req.headers.authorization = 'Bearer ' + authorization
		}
		next()
	}
}
